<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      思路：https://leetcode-cn.com/problems/house-robber-iii/solution/si-chong-xie-fa-di-gui-ji-yi-hua-di-gui-shu-xing-d/
    */
    var rob = function(root) {
      if (!root) return 0;

      let robIncludeRoot = root.val;
      if (root.left)
        robIncludeRoot += rob(root.left.left) + rob(root.left.right);
      if (root.right)
        robIncludeRoot += rob(root.right.left) + rob(root.right.right);
      
      let robExcludeRoot = rob(root.left) + rob(root.right);

      return Math.max(robIncludeRoot, robExcludeRoot);
    };
  </script>
</body>
</html>